package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import com.itheima.constant.MessageConstant;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * 类 名: SetmealMobileController
 * 描 述:
 * 作 者: 蔡畅
 * 创 建：2019年11月25日
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealMobileController {

    @Reference
    public SetmealService setmealService;


    //获取所有套餐信息
    @RequestMapping("/getSetmeal")
    public Result getSetmeal() {

        try {
            //查询所有套餐//
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);

        }

    }


    //根据id查询
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        try {
            Setmeal setmeal = setmealService.getSetmealById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
